package cn.mcch.investigator.viewdelegate.impl;

import android.support.v4.view.ViewPager;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import cn.mcch.investigator.R;
import cn.mcch.investigator.listener.OnCommonClickListener;
import cn.mcch.investigator.viewdelegate.IMainViewDelegate;
import cn.mcch.investigator.viewdelegate.BaseViewDelegate;

/**
 * Created by Administrator on 2016/12/16.
 */
public class MainViewDelegateImpl extends BaseViewDelegate implements IMainViewDelegate{

    @Override
    public void initEventsListener(OnCommonClickListener l) {
        setOnClickListener(l, R.id.tv_create_task, R.id.tv_my_task, R.id.tv_find, R.id.tv_update_password, R.id.tv_exit);
        addOnPageChangeListener(l, R.id.vp_content);
    }

    public void toogle() {
        DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.dl_main);
        if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
            drawerLayout.closeDrawer(GravityCompat.START);
        } else {
            drawerLayout.openDrawer(GravityCompat.START);
        }
    }

    public void setOffscreenPageLimit(int limit) {
        ((ViewPager) findViewById(R.id.vp_content)).setOffscreenPageLimit(limit);
    }

    public void setCurrentItem(int position) {
        ((ViewPager) findViewById(R.id.vp_content)).setCurrentItem(position,false);
    }

    @Override
    public boolean isDrawerOpen() {
        DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.dl_main);
        return drawerLayout.isDrawerOpen(GravityCompat.START);
    }
}
